(function (param) {
  console.log("second");
  // 头部组件
  const Header = window.VueComponents.Header;
  // 底部组件
  const Footer = window.VueComponents.Footer;
  // 卡片组件
  const CardCom = window.VueComponents.CardCom;
  const CardHead = window.VueComponents.CardHead;
  // 排行榜列表组件
  const TopList = window.VueComponents.TopList;
  // 咨询列表组件
  const ConsultCom = window.VueComponents.ConsultCom;
  // 影视列表组件
  const VideoList = window.VueComponents.VideoList;

  Vue.createApp({
    components: {
      HeaderCom: Header,
      CardCom,
      CardHead,
      HeaderCom: Header,
      FooterCom: Footer,
      TopList,
      ConsultCom,
      VideoList,
    },
    data: () => ({
      query: {},
      dataInfo: {},
      // 对应类型的数据 热榜单
      hotTypeData: [],
      // 影视数据
      moviesData: [],
      hotList: [
        "非凡医者",
        "侏罗纪世界3",
        "狂飙",
        "欢迎来到麦乐村",
        "孤注一掷",
        "一路朝阳",
        "消失的她",
        "鹊刀门传奇",
        "回来的女儿",
        "长相思",
        "八角笼中",
        "玉骨遥",
        "梅花红桃",
        "三体",
        "田耕纪",
      ],
    }),
    created() {
      //  数据初始化
      this.navInit();
      this.initHotdata(); //处理热度裴航数据
      this.initMoviesData(); //处理影视数据
    },
    methods: {
      // 初始化
      navInit() {
        // 获取url参数
        const query = this.getQueryVariable();
        const id = query.id ? Number(query.id) : null;
        const type = query.type ? Number(query.type) : null;
        const tag = query.tag ? Number(query.tag) : null;
        const isHot = query.hot ? Number(query.hot) : false;
        this.query = { id, type, tag };
        if (id != null && type != null && tag != null) {
          this.searchMovies(id, type, tag, isHot);
        } else {
          alert("参数错误");
          window.location.replace("./index.html");
        }
      },
      // 查找对应数据
      searchMovies(id = 0, type = 0, tag = 0, isHot = false) {
        console.log(type, id, tag, isHot);
        const TagData = window.APIDATA.TagData;
        const HotData = window.APIDATA.HotData;
        const TypeData = window.APIDATA.TypeData;
        let result = {};
        let useFindData = [];
        try {
          if (isHot) {
            useFindData = HotData(type)[tag];
          } else {
            // 影视数据
            useFindData = TypeData(type)[tag];
          }
          const findObj = useFindData.find((e) => id == e.season_id);
          if (!findObj) {
            alert("没有找到对应数据");
            return;
          }
          result = {
            title: findObj.title,
            order: findObj.order,
            score: findObj.score,
            subTitle: findObj.subTitle,
            index_show: findObj.index_show,
            cover: findObj.cover,
            type: TagData(type)[tag],
          };
          Object.assign(this.dataInfo, result);
        } catch (error) {
          console.error("参数错误~~~");
          alert("参数错误");
          window.location.replace("./index.html");
        }
      },
      // 处理热度数据
      initHotdata() {
        try {
          // const { tag,type } = this.query
          let type = this.query.type;
          let tag = this.query.tag;
          // console.log(tag, type);
          // const TagData = window.APIDATA.TagData;
          const HotData = window.APIDATA.HotData;
          // const TypeData = window.APIDATA.TypeData;

          const useData = HotData(type)[tag];
          // console.log(useData)
          this.hotTypeData = useData.splice(0, 20).map((item) => ({
            id: item.season_id,
            title: item.title,
            muted: item.order,
            href: `second.html?id=${item.season_id}&type=${type}&tag=${tag}&hot=1`,
          }));
        } catch (error) {}
      },

      initMoviesData() {
        let type = this.query.type;
        let tag = this.query.tag;
        const TagData = window.APIDATA.TagData;
        const TypeData = window.APIDATA.TypeData;

        const useData = TypeData(type)[tag];
        this.moviesData = useData.splice(0, 18).map((item) => ({
          id: item.season_id,
          title: item.title,
          pic: item.order,
          desc: item.subTitle,
          img: item.cover,
          href: `second.html?id=${item.season_id}&type=${type}&tag=${tag}`,
        }));
      
      },

      getQueryVariable(variable) {
        let query = window.location.search.substring(1);
        let vars = query.split("&");
        let queryValue = {};
        vars.forEach((pair) => {
          if (pair.indexOf("=") != -1) {
            const item = pair.split("=");
            queryValue[item[0]] = item[1];
          }
        });
        return queryValue;
      },
    },
  }).mount("#app-second");
})();
